
	
	
--api
------------------------------------------------------------------------

local log_node_prototype =
{
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
	sounds = generic_media.node_sound_wood_defaults(),
	on_place = minetest.rotate_node
}

local plank_node_prototype =
{
	paramtype2 = "facedir",
	place_param2 = 0,
	is_ground_content = false,
	groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1},
	sounds = generic_media.node_sound_wood_defaults(),
}

local leaf_node_prototype =
{
	drawtype = "allfaces_optional",
	waving = 1,
	paramtype = "light",
	is_ground_content = false,
	groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
	sounds = generic_media.node_sound_leaves_defaults(),
	on_break = function() end,
}

local wood_item_prototype = 
{
	groups =
	{
		wood = 1,
	}		
}


local function get_definition(which)
	local orig
	if which == "log"
	then
		orig = log_node_prototype
	elseif which == "plank"
	then
		orig = plank_node_prototype
	elseif which == "leaf"
	then
		orig = leaf_node_prototype
	elseif which == "item"
	then
		orig = wood_item_prototype
	end
	
	
	local def = {}
	for k, v in pairs(orig)
	do
		def[k] = v
	end
	return def
end

local nodetypes =
{
	log = function(name, ndef, def)
		ndef.tiles = {def.toptexture, def.toptexture, def.sidetexture}
		ndef.drop = "log"
		return name .. "_log"
	end,
	plank = function(name, ndef, def)
		ndef.tiles = {def.texture}
		ndef.drop = "plank"
		return name .. "_plank"
	end,
	leaf = function(name, ndef, def)
		ndef.tiles = {def.normaltexture}
		ndef.special_tiles = {def.simpletexture}
		ndef.drop = ""
		return name .. "_leaves"
	end,
	
}
local function register_node(type, name, def)
	if not def --everything's optional
	then
		return
	end
	local ndef = get_definition(type)
	ndef.description = def.description
	local regname = nodetypes[type](name, ndef, def) --node type specific modification
	
	minetest.register_node(regname, ndef)
end

--[[ Unused in The End, but potentially useful for other games

local itemtypes =
{
	log = function(name, idef, def)
		idef._sawing_result = name .. "_plank_item"
		return name .. "_log_item"
	end,
	plank = function(name, idef, def)
		idef._sawing_result = "stick"
		return name .. "_plank_item"
	end

}

local function register_item(type, name, def)
	if not def
	then
		return
	end
	local idef = get_definition("item")
	idef.description = def.description
	idef.inventory_image = def.itemtexture
	local regname = itemtypes[type](name, idef, def)
	minetest.register_craftitem(regname, idef)
end

]]

function wood_and_saws.register_wood(name, def)
	register_node("log", name, def.log)
	register_node("plank", name, def.plank)
	register_node("leaf", name, def.leaf)
	
	--register_item("log", name, def.log)
	--register_item("plank", name, def.plank)
end

